<form action="index.php/payment_record/insert/" method="post" name="myform" id="myform">
<div id="inline5">
<h2><span>详细信息</span></h2>
<table>
        <tr><th colspan="5">回款记录：</th></tr>
        <tr>
            <td class="name" width="100"><span>*</span>客户：</td>
            <td colspan="4"><input id="customer_name" autocomplete="off" style="" type="text" name="customer_name" value=></input></td>
        </tr>
        <tr>
        	<td class="name" width="100">合同/订单：</td>
            <td colspan="4">
				<select id="plan_contacter_name" name="contract_id" style=" width:275px;">
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">期次：</td>
            <td>
            	<select name="stages" id="record_stages">
            	    <?php //for($i=1;$i<=12;$i++){?>
                	<!-- <option value="<?= $i?>" <?php if($payment_record->stages == $i):?>selected="selected"<?php endif;?>><?php echo $i;?></option> -->
                    <?php //}?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">日期：</td>
            <td><input name="payment_time" type="text" class="datepicker" id="find_time"  style="background:url(images/calendar.gif) right 1px no-repeat;" value= ></input></td>
        </tr>

        <tr>
            <td class="name" width="100">金额：</td>
            <td><input class="input_bg" name="money" type="text" id="principal" value= ></input></td>
        </tr>
        <tr>
            <td class="name" width="100">以开发票：</td>
            <td>
            	<select name="bill">
                	<option value="1">是</option>
                    <option value="0">否</option>
                    <option value="-1">无需开票</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">付款方式：</td>
            <td>
            	<select name="payment_method">
                	<option value="支票">支票</option>
                    <option value="现金">现金</option>
                    <option value="银行转帐">银行转帐</option>
                    <option value="其它">其它</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">所有者：</td>
            <td>
            	<select name="owner_id" style=" width:275px;">
                	<?php foreach($users as $user):?>
                		<?php if($user->user_name != '何俊斌'):?>
                			<option value="<?= $user->id?>" <?php if($this->session->userdata('username') == $user->user_name):?>selected="selected"<?php endif;?>><?= $user->user_name?></option>
            			<?php endif;?>
                	<?php endforeach;?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="100">备注：</td>
            <td>
            	<textarea name="remark"></textarea>
            </td>
        </tr>
        <tr><td>&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="record_tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset""重置" /></td>
        </tr>
    </table>
</div>
</form>
<input type="hidden" id="type" value="2" ></input>
<input type="hidden" id="type_record" value="1" ></input>
<script type="text/javascript">
$(function() {
		$( ".datepicker" ).datepicker();

		$("#plan_contacter_name").change(function(){
			$("#record_stages").html('');
			var plan_id = $("#plan_contacter_name").val();
				$.ajax({
	                type: "POST",
	                dataType: "text",
	                url: "index.php/payment_record/get_plan_stages",
	                data: "plan_id="+plan_id,
	                success: function(data) {
	                	var array='';
	                	data=$.parseJSON(data);
	                	var nums = data['nums']; //实际期次
	                	var stages = data['stages']; //总期次
	                	if(nums == stages){
	                		for(var i=1;i<=nums;i++){
		                		array+="<option>"+i+"</option>";
			                }
			             }else{
			            	 for(var i=0;i<nums;i++){
			                		array+="<option>"+(stages-i)+"</option>";
				             }
				         }
	                	$("#record_stages").append(array);
	                }
	            });
		})

		$("#principal").blur(function(){
			var money = $("#principal").val();
			if(isNaN(money)){
				alert('不是数字');
				$("#principal").val('');
				}
		})

		$("#record_tijiao").click(function(){
			var customer_name = $("#customer_name").val();
			if(customer_name == ''){
				alert('客户不能为空');
				$("#customer_name").focus();
				}else{
					var contarct_id = $("#plan_contacter_name").val();
					var input_money = $("#principal").val();
					$.post("index.php/payment_record/check_add_record_money", { contarct_id: contarct_id ,input_money: input_money },
							   function(data){
							    if(data){
								    alert('输入的金额过大');
								    $("#principal").focus();
								 }else{
									 $("#myform").submit();
									 }
					});
				}
		})
});
</script>